package io.gitee.yth.design.pattern.test.core.pattern.behavioral.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @author yth
 * @since 2023-04-30-15:25
 */
public abstract class AbstractSubject implements ISubject {

    private final List<IObserver> observers = new ArrayList<>();

    public void attach(IObserver observer) {
        observers.add(observer);
    }

    public void detach(IObserver observer) {
        observers.remove(observer);
    }

    public void notifyObservers() {
        observers.forEach(e -> e.update(this));
    }
}
